package com.stark.commons.spring.web.support.zuul;

import org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequest;
import org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient;
import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;
import org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommand;

import com.stark.commons.spring.web.boot.properties.ZuulTimeoutProperties;

/**
 * 扩展 {@link org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommand} ,
 * 使用自定义的 {@link com.stark.commons.spring.web.support.zuul.CustomRibbonApacheHttpRequest} ,
 * 支持 uri 接口级别的超时配置。
 * 
 * @author Ben
 * @since 1.0.0
 * @version 1.0.0
 * @see org.springframework.cloud.netflix.zuul.filters.route.apache.HttpClientRibbonCommand
 * @see com.stark.commons.spring.web.support.zuul.CustomRibbonApacheHttpRequest
 */
public class CustomHttpClientRibbonCommand extends HttpClientRibbonCommand {
	
	private final ZuulTimeoutProperties zuulTimeoutProperties;

	public CustomHttpClientRibbonCommand(String serviceId, RibbonLoadBalancingHttpClient client,
			RibbonCommandContext context, ZuulProperties zuulProperties, FallbackProvider zuulFallbackProvider,
			ZuulTimeoutProperties zuulTimeoutProperties) {
		super(serviceId, client, context, zuulProperties, zuulFallbackProvider);
		this.zuulTimeoutProperties = zuulTimeoutProperties;
	}
	
	@Override
	protected RibbonApacheHttpRequest createRequest() throws Exception {
		return new CustomRibbonApacheHttpRequest(context, zuulTimeoutProperties);
	}

}
